﻿#include "scrolledstackedwidget.h"
#include "mainwindow.h"


scrolledStackedWidget::scrolledStackedWidget(QList<QWidget *> & pages,QWidget *parent) :
    QWidget(parent)
{
    stackWidget = new QStackedWidget(this);

    for(int i=0; i < pages.count(); ++i)
    {
        pages[i]->setSizePolicy(QSizePolicy::Ignored,QSizePolicy::Ignored);
        stackWidget->addWidget( pages[i] );
    }

    scrollArea= new QScrollArea(this);
    scrollArea->setWidget( stackWidget );
    scrollArea->setFrameShape (QFrame::NoFrame);

    QHBoxLayout *layout = new QHBoxLayout(this);
    layout->setMargin(0);
    layout->addWidget(scrollArea);
}

QString scrolledStackedWidget::currentPageName()
{
    return stackWidget->currentWidget()->accessibleName();
}

void scrolledStackedWidget::changePage(int idx)
{
    if (stackWidget->currentWidget() !=0) {
        stackWidget->currentWidget()->setSizePolicy(QSizePolicy::Ignored,
                                                    QSizePolicy::Ignored);
    }
    stackWidget->setCurrentIndex(idx);
    stackWidget->currentWidget()->setSizePolicy(QSizePolicy::Expanding,
                                                QSizePolicy::Expanding);
    stackWidget->adjustSize();
}
